/**
 * 事件解释器
 * @param eventJson
 * @returns {EventInterpreter}
 * @constructor
 */
export const EventInterpreter = function (eventJson){
  this.eventJson = eventJson
  return this
}
/**
 * 解释事件
 * @returns {function(*=, *=): (boolean|undefined)}
 */
EventInterpreter.prototype.explain = function (){
  console.log(this.eventJson)
  const that = this;
  return function (val, oldVal) {
    if(_.isEmpty(that.eventJson) || _.isEmpty(that.eventJson.events)){
      return false
    }
    _.each(that.eventJson.events, (e) => {
      const condition = that.generateCondition(e.conditions)
      if(condition) {
        const con = condition(val, oldVal)
        if(con){
          that.handleAction(this, val, oldVal)
        }
      }
    })
  }
}

const LOGIC = {
  // '与': &&
}

/**
 * 生成条件函数
 * @param condition
 */
EventInterpreter.prototype.generateCondition = function (condition){
  console.log(condition)
  _.each(condition, (con) => {
    // if()
  })
}
/**
 * 处理动作
 * @param field
 * @param val
 * @param oldVal
 */
EventInterpreter.prototype.handleAction = function (field, val, oldVal){

}

EventInterpreter.prototype.conditionMappings = {
  equals: function(compare, val){
    return compare === val
  },
  not_equals: function(compare, val){
    return compare !== val
  },
}

